home *** CD-ROM | disk | FTP | other *** search
- -- emove.e
- -- move the Enterprise
-
- -- energy consumed per ship movement at warp 0..5
- constant fuel = {0, 5, 8, 12, 30, 60}
-
- global function gmod(positive_int x)
- -- quadrant wraparound
- if x = 0 then
- return G_SIZE
- elsif x > G_SIZE then
- return 1
- else
- return x
- end if
- end function
-
-
- -- standard row in f array for a type
- global constant stdtype =
- -- TYPE EN TORP DEFL FRATE MRATE TARG
- {{}, -- dummy (Enterprise)
- {G_SK, 4000, 1, 0, 100, 140, ENTERPRISE}, -- small Klingon
- {G_BK, 8000, 2, 0, 100, 180, ENTERPRISE}, -- big Klingon
- {G_JM, 16000, 4, 0, 150, 220, ENTERPRISE}, -- Jumbo
- {G_RM, 2000, 1, 0, 70, 150, ENTERPRISE}, -- Romulan
- {G_TH, 3000, 0, 0, 50, 80, -1}, -- Tholian
- {G_PL, 3000, 0, 0, 0, 0, -1}, -- planet
- {G_BS, 3500, 2, 1, 120, 0, -1}} -- base
-
- procedure setupf()
- -- set up f array for a new quadrant
-
- positive_int slen
- sequence g_info
-
- slen = length(stdtype[G_PL])
- g_info = g[qrow][qcol]
-
- fb1 = g_info[G_PL] + 2
- for row = 2 to fb1-1 do
- f[row][1..slen] = stdtype[G_PL]
- f[row][F_DOCK] = FALSE
- end for
-
- fr1 = g_info[G_BS] + fb1
- for row = fb1 to fr1-1 do
- f[row][1..slen] = stdtype[G_BS]
- f[row][F_DOCK] = FALSE
- end for
-
- ft1 = g_info[G_RM] + fr1
- rtarg = -1
- for row = fr1 to ft1-1 do
- f[row][1..slen] = stdtype[G_RM]
- f[row][F_UNDER] = repeat(' ', length(ship[G_RM][1]))
- rtarg = ENTERPRISE
- end for
-
- fk1 = g_info[G_TH] + ft1
- for row = ft1 to fk1-1 do
- f[row][1..slen] = stdtype[G_TH]
- f[row][F_UNDER] = repeat(' ', length(ship[G_TH][1]))
- end for
-
- fnext = g_info[G_JM] + fk1
- for row = fk1 to fnext-1 do
- f[row][1..slen] = stdtype[G_JM]
- f[row][F_UNDER] = repeat(' ', length(ship[G_JM][1]))
- end for
-
- for row = fnext to fnext + g_info[G_BK] - 1 do
- f[row][1..slen] = stdtype[G_BK]
- f[row][F_UNDER] = repeat(' ', length(ship[G_BK][1]))
- end for
- fnext = fnext + g_info[G_BK]
-
- for row = fnext to fnext + g_info[G_SK] - 1 do
- f[row][1..slen] = stdtype[G_SK]
- f[row][F_UNDER] = repeat(' ', length(ship[G_SK][1]))
- end for
- fnext = fnext + g_info[G_SK]
- end procedure
-
- function dock(h_coord x, v_coord y)
- -- Enterprise docks with a base or planet
-
- object_type t
- valid_f_row r
- pb_row pbr
- positive_int maxen, torp, availtorp
- positive_atom energy, availen
-
- if curwarp != 1 then
- return FALSE
- else
- r = flook(x, y, TRUE)
- t = f[r][F_TYPE]
- if t = G_PL or t = G_BS then
- if not f[r][F_DOCK] then
- f[r][F_DOCK] = TRUE
- pbr = f[r][F_PBX]
- pb[pbr][P_EXIST] = DOCKED_WITH
- if pb[pbr][P_POD] > 0 then
- pb[pbr][P_POD] = pb[pbr][P_POD] - 1
- ps = ps & POD
- end if
- torp = 5 - f[ENTERPRISE][F_TORP]
- availtorp = pb[pbr][P_TORP]
- if torp > availtorp then
- torp = availtorp
- end if
- pb[pbr][P_TORP] = availtorp - torp
- torp = torp + f[ENTERPRISE][F_TORP]
- f[ENTERPRISE][F_TORP] = torp
- ts = repeat(TORPEDO, torp)
- if t = G_BS then
- for i = 1 to NSYS do
- if reptime[i] then
- reptime[i] = 0
- repair(i)
- end if
- end for
- if gal then
- esyml = ENTERPRISE_L
- esymr = ENTERPRISE_R
- if esym[1] = SHUTTLE_L[1] then
- esym = ENTERPRISE_L
- else
- esym = ENTERPRISE_R
- end if
- otype[G_EN] = "EUPHORIA"
- gal = FALSE
- end if
- end if
- if gal then
- maxen = 5000
- else
- maxen = 30000
- end if
- energy = maxen - f[ENTERPRISE][F_EN]
- availen = pb[pbr][P_EN]
- if energy > availen then
- energy = availen
- end if
- if t = G_BS then
- if torp > 0 or energy > 0 then
- f[ENTERPRISE][F_DEFL] = 3
- ds = repeat(DEFLECTOR, 3)
- end if
- end if
- pb[pbr][P_EN] = availen - energy
- energy = energy + f[ENTERPRISE][F_EN]
- if energy > maxen then
- energy = maxen
- end if
- f[ENTERPRISE][F_EN] = energy
- p_energy(0)
- wtext()
- docking_sound()
- msg("DOCKING COMPLETED")
- if scanon then
- dsyms()
- end if
- return TRUE
- end if
- end if
- end if
- return FALSE
- end function
-
- type increment(integer x)
- return x = -1 or x = 0 or x = +1
- end type
-
- global procedure t2emove()
- -- task 2: move the Enterprise
- h_coord x, exold
- v_coord y, eyold
- increment eqx, eqy
- sequence c, sc1
-
- if curwarp > wlimit then
- if curwarp - wlimit > rand(12) then
- sounde(5, 20, 1)
- msg("ALL ENGINES DAMAGED")
- wlimit = 0
- reptime[ENGINES] = reptime[ENGINES] + rand(11)
- setwarp(0)
- return
- end if
- end if
- sounde(4, 3, 1)
- eqx = 0
- eqy = 0
- exold = f[ENTERPRISE][F_X]
- eyold = f[ENTERPRISE][F_Y]
- f[ENTERPRISE][F_X] = f[ENTERPRISE][F_X] + exi
- f[ENTERPRISE][F_Y] = f[ENTERPRISE][F_Y] + eyi
-
- -- check for switching quadrants:
-
- if f[ENTERPRISE][F_X] > HSIZE - length(esym) + 1 then
- f[ENTERPRISE][F_X] = 1
- eqx = 1
- elsif f[ENTERPRISE][F_X] < 1 then
- f[ENTERPRISE][F_X] = HSIZE - length(esym) + 1
- eqx = -1
- end if
-
- if f[ENTERPRISE][F_Y] = VSIZE + 1 then
- f[ENTERPRISE][F_Y] = 1
- eqy = 1
- elsif f[ENTERPRISE][F_Y] = 0 then
- f[ENTERPRISE][F_Y] = VSIZE
- eqy = -1
- end if
-
- if gal then
- p_energy(-fuel[curwarp+1]/6)
- else
- p_energy(-fuel[curwarp+1])
- end if
-
- c = f[ENTERPRISE][F_UNDER]
- write_screen(exold, eyold, c)
- if eqx != 0 or eqy != 0 then
- -- new quadrant
- qcol = gmod(qcol + eqx)
- qrow = gmod(qrow + eqy)
- setupf()
- for i = ft1 to fk1-1 do
- f[i][F_TARG] = tholian_target(i)
- end for
- position(QUAD_LINE, 44)
- set_bk_color(CYAN)
- set_color(MAGENTA)
- printf(CRT, "%d.%d", {qrow, qcol})
- g[qrow][qcol][1] = TRUE
- msg("")
- gsbox(qrow, qcol)
- pobj()
- end if
- x = f[ENTERPRISE][F_X]
- y = f[ENTERPRISE][F_Y]
- sc1 = read_screen({x, length(esym)}, y)
- if find(TRUE, sc1 != ' ' and sc1 != STAR) then
- -- there's something in our way
- if not dock(x, y) then
- if scanon then
- setg1()
- end if
- end if
- f[ENTERPRISE][F_X] = exold
- f[ENTERPRISE][F_Y] = eyold
- end if
- c = read_screen({f[ENTERPRISE][F_X], length(esym)}, f[ENTERPRISE][F_Y])
- f[ENTERPRISE][F_UNDER] = c
- write_screen(f[ENTERPRISE][F_X], f[ENTERPRISE][F_Y], esym)
- end procedure
-
-
-